<!DOCTYPE html>
<html lang="en">
  <head>
    <title>SingleUserDefaultsStore Class Reference</title>
    <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
    <meta charset="utf-8">
    <script src="../js/jquery.min.js" defer></script>
    <script src="../js/jazzy.js" defer></script>
    
    <script src="../js/lunr.min.js" defer></script>
    <script src="../js/typeahead.jquery.js" defer></script>
    <script src="../js/jazzy.search.js" defer></script>
  </head>
  <body>

    <a name="//apple_ref/swift/Class/SingleUserDefaultsStore" class="dashAnchor"></a>

    <a title="SingleUserDefaultsStore Class Reference"></a>

    <header class="header">
      <p class="header-col header-col--primary">
        <a class="header-link" href="../index.html">
          UserDefaultsStore 2.0.0 Docs
        </a>
         (100% documented)
      </p>
    
      <p class="header-col--secondary">
        <form role="search" action="../search.json">
          <input type="text" placeholder="Search documentation" data-typeahead>
        </form>
      </p>
    
    
    </header>

    <p class="breadcrumbs">
      <a class="breadcrumb" href="../index.html">UserDefaultsStore Reference</a>
      <img class="carat" src="../img/carat.png" />
      SingleUserDefaultsStore Class Reference
    </p>

    <div class="content-wrapper">
      <nav class="navigation">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/SingleUserDefaultsStore.html">SingleUserDefaultsStore</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/SingleUserDefaultsStore/Snapshot.html">– Snapshot</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/UserDefaultsStore.html">UserDefaultsStore</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/UserDefaultsStore/Snapshot.html">– Snapshot</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">

        <section class="section">
          <div class="section-content top-matter">
            <h1>SingleUserDefaultsStore</h1>
              <div class="declaration">
                <div class="language">
                  
                  <pre class="highlight swift"><code><span class="kd">open</span> <span class="kd">class</span> <span class="kt">SingleUserDefaultsStore</span><span class="o">&lt;</span><span class="kt">Object</span><span class="o">&gt;</span> <span class="k">where</span> <span class="kt">Object</span> <span class="p">:</span> <span class="kt">Decodable</span><span class="p">,</span> <span class="kt">Object</span> <span class="p">:</span> <span class="kt">Encodable</span></code></pre>

                </div>
              </div>
            <p><code>SingleUserDefaultsStore</code> offers a convenient way to store a single <code>Codable</code> object in <code>UserDefaults</code>.</p>

          </div>
        </section>

        <section class="section">
          <div class="section-content">
            <div class="task-group">
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C8SnapshotV"></a>
                    <a name="//apple_ref/swift/Struct/Snapshot" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C8SnapshotV">Snapshot</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Used to backup and restore content to store.</p>

                        <a href="../Classes/SingleUserDefaultsStore/Snapshot.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">struct</span> <span class="kt">Snapshot</span> <span class="p">:</span> <span class="kt">Codable</span></code></pre>
<pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt"><a href="../Classes/SingleUserDefaultsStore.html">SingleUserDefaultsStore</a></span><span class="o">.</span><span class="kt">Snapshot</span><span class="p">:</span> <span class="kt">Equatable</span> <span class="k">where</span> <span class="kt">Object</span><span class="p">:</span> <span class="kt">Equatable</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C16uniqueIdentifierSSvp"></a>
                    <a name="//apple_ref/swift/Property/uniqueIdentifier" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C16uniqueIdentifierSSvp">uniqueIdentifier</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Store&rsquo;s unique identifier.</p>

<p><strong>Warning</strong>: Never use the same identifier for two -or more- different stores.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">let</span> <span class="nv">uniqueIdentifier</span><span class="p">:</span> <span class="kt">String</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C7encoder10Foundation11JSONEncoderCvp"></a>
                    <a name="//apple_ref/swift/Property/encoder" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C7encoder10Foundation11JSONEncoderCvp">encoder</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>JSON encoder to be used for encoding object to be stored.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">open</span> <span class="k">var</span> <span class="nv">encoder</span><span class="p">:</span> <span class="kt">JSONEncoder</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C7decoder10Foundation11JSONDecoderCvp"></a>
                    <a name="//apple_ref/swift/Property/decoder" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C7decoder10Foundation11JSONDecoderCvp">decoder</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>JSON decoder to be used to decode the stored object.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">open</span> <span class="k">var</span> <span class="nv">decoder</span><span class="p">:</span> <span class="kt">JSONDecoder</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C16uniqueIdentifier7encoder7decoderACyxGSS_10Foundation11JSONEncoderCAH11JSONDecoderCtcfc"></a>
                    <a name="//apple_ref/swift/Method/init(uniqueIdentifier:encoder:decoder:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C16uniqueIdentifier7encoder7decoderACyxGSS_10Foundation11JSONEncoderCAH11JSONDecoderCtcfc">init(uniqueIdentifier:<wbr>encoder:<wbr>decoder:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Initialize store with given identifier. <em>O(1)</em></p>

<p><strong>Warning</strong>: Never use the same identifier for two -or more- different stores.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">required</span> <span class="kd">public</span> <span class="nf">init</span><span class="p">(</span>
    <span class="nv">uniqueIdentifier</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span>
    <span class="nv">encoder</span><span class="p">:</span> <span class="kt">JSONEncoder</span> <span class="o">=</span> <span class="o">.</span><span class="nf">init</span><span class="p">(),</span>
    <span class="nv">decoder</span><span class="p">:</span> <span class="kt">JSONDecoder</span> <span class="o">=</span> <span class="o">.</span><span class="nf">init</span><span class="p">()</span>
<span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>uniqueIdentifier</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>store&rsquo;s unique identifier.</p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>encoder</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>JSON encoder to be used for encoding object to be stored. <em>default is <code>JSONEncoder()</code></em></p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>decoder</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>JSON decoder to be used to decode the stored object. <em>default is <code>JSONDecoder()</code></em></p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C4saveyyxKF"></a>
                    <a name="//apple_ref/swift/Method/save(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C4saveyyxKF">save(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Save object to store. <em>O(1)</em></p>
<div class="aside aside-throws">
    <p class="aside-title">Throws</p>
    JSON encoding error.

</div>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">save</span><span class="p">(</span><span class="n">_</span> <span class="nv">object</span><span class="p">:</span> <span class="kt">Object</span><span class="p">)</span> <span class="k">throws</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>object</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>object to save.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C6objectxSgvp"></a>
                    <a name="//apple_ref/swift/Property/object" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C6objectxSgvp">object</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Get object from store. <em>O(1)</em></p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">object</span><span class="p">:</span> <span class="kt">Object</span><span class="p">?</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C6deleteyyF"></a>
                    <a name="//apple_ref/swift/Method/delete()" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C6deleteyyF">delete()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Delete object from store. <em>O(1)</em></p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">delete</span><span class="p">()</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C16generateSnapshotAC0F0Vyx_GyF"></a>
                    <a name="//apple_ref/swift/Method/generateSnapshot()" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C16generateSnapshotAC0F0Vyx_GyF">generateSnapshot()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Generate a snapshot that can be saved and restored later. <em>O(1)</em></p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">generateSnapshot</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt"><a href="../Classes/SingleUserDefaultsStore/Snapshot.html">Snapshot</a></span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p><code><a href="../Classes/SingleUserDefaultsStore/Snapshot.html">Snapshot</a></code> object representing current contents of the store.</p>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C15restoreSnapshotyyAC0F0Vyx_GKF"></a>
                    <a name="//apple_ref/swift/Method/restoreSnapshot(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C15restoreSnapshotyyAC0F0Vyx_GKF">restoreSnapshot(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Restore a pre-generated <code><a href="../Classes/SingleUserDefaultsStore/Snapshot.html">Snapshot</a></code>. <em>O(1)</em></p>
<div class="aside aside-throws">
    <p class="aside-title">Throws</p>
    JSON encoding/decoding error.

</div>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">restoreSnapshot</span><span class="p">(</span><span class="n">_</span> <span class="nv">snapshot</span><span class="p">:</span> <span class="kt"><a href="../Classes/SingleUserDefaultsStore/Snapshot.html">Snapshot</a></span><span class="p">)</span> <span class="k">throws</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>snapshot</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p><code><a href="../Classes/SingleUserDefaultsStore/Snapshot.html">Snapshot</a></code> to restore.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C16lastSnapshotDate10Foundation0G0VSgvp"></a>
                    <a name="//apple_ref/swift/Property/lastSnapshotDate" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C16lastSnapshotDate10Foundation0G0VSgvp">lastSnapshotDate</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Date when the last <code><a href="../Classes/SingleUserDefaultsStore/Snapshot.html">Snapshot</a></code> was generated.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">lastSnapshotDate</span><span class="p">:</span> <span class="kt">Date</span><span class="p">?</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:17UserDefaultsStore06SingleabC0C15lastRestoreDate10Foundation0G0VSgvp"></a>
                    <a name="//apple_ref/swift/Property/lastRestoreDate" class="dashAnchor"></a>
                    <a class="token" href="#/s:17UserDefaultsStore06SingleabC0C15lastRestoreDate10Foundation0G0VSgvp">lastRestoreDate</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Date when the last <code><a href="../Classes/SingleUserDefaultsStore/Snapshot.html">Snapshot</a></code> was successfully restored.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">lastRestoreDate</span><span class="p">:</span> <span class="kt">Date</span><span class="p">?</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </section>

      </article>
    </div>
    <section class="footer">
      <p>&copy; 2020 <a class="link" href="https://github.com/omaralbeik/UserDefaultsStore" target="_blank" rel="external">Omar Albeik</a>. All rights reserved. (Last updated: 2020-08-21)</p>
      <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.5</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
    </section>
  </body>
</div>
</html>
